App.controller('contactUsController', ['$rootScope', '$scope', '$state', 'Page', function ($rootScope, $scope, $state, Page) {
    $scope.contactUsGrid = {
        column_defs: [
	            {
					target: 2,
					buttons: [
						{
							name: '编辑',
							class: 'btn-edit',
							icon: 'fa-edit',
							event: 'updateContactUs'
						},
						{
							name: '删除',
							class: 'btn-danger',
							icon: 'fa-edit',
							event: 'deleteContactUs'
						}
					]
				}
        ],
		updateContactUs : function(row){
			$scope.addFlag = false;
			$scope.contactUs = row;
			$scope.contactUsAddModal.show();
		},
		deleteContactUs : function(row){
			$scope.contactUs = row;
			 Page.confirm("确定要删除吗?", function () {
                Page.ajaxPost('contactUs/delete.do', $scope.contactUs, function () {
                	Page.notice("删除成功");
    				$scope.contactUsGrid.query();
    			});
			 });
		},
		addContactUs : function(){
			$scope.notice = {};
			$scope.addFlag = true;
			$scope.contactUsAddModal.show();
		},
		save : function(){// 保存
			var url = "";
			if($scope.addFlag){
				url = "contactUs/add.do";
			}else {
				url = "contactUs/update.do";
			}
			Page.ajaxPost(url, $scope.contactUs, function () {
				Page.notice("操作成功");
				$scope.contactUsGrid.query();
				$scope.contactUsAddModal.hide();
			});
		},
		cancel : function(){
			$scope.contactUsAddModal.hide();
		}
    };
}]);
